package com.gzk.hrm.web.controller;

import com.gzk.hrm.query.CourseQuery;
import com.gzk.hrm.service.ICourseElasticSearchService;
import com.gzk.hrm.util.AjaxResult;
import com.gzk.hrm.doc.CourseDoc;
import com.gzk.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CourseElasticSearchController {

    @Autowired
    private ICourseElasticSearchService courseElasticSearchService;


    @PreAuthorize("hasAuthority('es:addCourse')")
    @RequestMapping(value = "/es/saveCourse",method = RequestMethod.POST)
    public AjaxResult saveCourse(@RequestBody CourseDoc doc){
        courseElasticSearchService.saveCourse(doc);
        return AjaxResult.me();
    }


    @RequestMapping(value = "/es/deleteCourse",method = RequestMethod.POST)
    public AjaxResult deleteCourse(@RequestBody Long id){
        courseElasticSearchService.deleteCourse(id);
        return AjaxResult.me();
    }


    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public AjaxResult searchCourse(@RequestBody CourseQuery query){
        PageList<CourseDoc> pagaList = courseElasticSearchService.searchCourse(query);
        return AjaxResult.me().setResultObj(pagaList);
    }


}
